package cn.zn.controller.flow;


import cn.zn.base.bean.dto.ResultData;
import cn.zn.base.common.utils.ResultUtil;
import cn.zn.flow.entity.Flow;
import cn.zn.flow.service.FlowService;
import cn.zn.flow.vo.FlowApproveVo;
import cn.zn.flow.vo.FlowPageVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 审批流程 前端控制器
 * </p>
 *
 * @author zn-admin
 * @since 2021-06-28
 */
@RestController
@RequestMapping("/flow/flow")
public class FlowController {

    @Autowired
    private FlowService flowService;

    /**
     * 获取流程
     *
     * @param id 授信id
     * @return 结果
     */
    @GetMapping(value = "/{id}")
    public ResultData info(@PathVariable String id, Boolean edit) {
        Flow flow = flowService.selectFlowInfo(id, edit);
        return ResultUtil.success(flow);
    }

    /**
     * 获取流程
     *
     * @param vo 条件
     * @return 结果
     */
    @GetMapping("/myList")
    public ResultData myList(FlowPageVo vo) {
        Object result = flowService.selectFlowListByUserCode(vo);
        return ResultUtil.success(result);
    }

    /**
     * 审批
     *
     * @param flowId 流程id
     * @param vo     审批结果
     * @return 结果
     */
    @PutMapping(value = "/approve/{flowId}")
    public ResultData approve(@PathVariable String flowId, @RequestBody FlowApproveVo vo) {
        flowService.approve(flowId, vo);
        return ResultUtil.success();
    }

}
